package com.fashionbrot.github.exception;


import com.fashionbrot.github.enums.RespEnum;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class MarsException extends RuntimeException {

    private int code;
    private String msg;


    public MarsException(String msg){
        super(msg);
        this.code = RespEnum.FAIL.getCode();
        this.msg = msg;
    }

    public MarsException(int code, String msg){
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public MarsException(RespEnum respCode){
        super(respCode.getMsg());
        this.code = respCode.getCode();
        this.msg = respCode.getMsg();
    }

    public MarsException(RespEnum respCode, String msg){
        super(respCode.getMsg());
        this.code = respCode.getCode();
        this.msg = msg+respCode.getMsg();
    }

    public static ThrowExceptionFunction isTrue(boolean b){

        return (errorMessage) -> {
            if (b){
                throw new MarsException(errorMessage);
            }
        };
    }

    public static void throwMsg(String msg){
        throw new MarsException(msg);
    }

}
